//
//  ViewController.m
//  KaKaWallet
//
//  Created by apple on 16/4/8.
//  Copyright © 2016年 ibendi. All rights reserved.
//

#import "ViewController.h"
#import "KaKaWallet-Swift.h" //  oc 引用swif 类 需要导入 项目名 -Swift.h
#import "AppDelegate.h"
#import "UserConfig.h"


@interface ViewController ()<UIScrollViewDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    if ([[NSUserDefaults standardUserDefaults] objectForKey:@"IS_FIRST_LOAD"]) {
        [self chageRootView];
    }else{
        [[NSUserDefaults standardUserDefaults] setObject:@"IS_FIRST_LOAD" forKey:@"IS_FIRST_LOAD"];
        [self addGutView];
    }
    
    
    UserConfig *user = [UserConfig SharedUser];
    user.token = @"fsdsd";
    user.userName = @"sssss";
    [UserConfig saveUser:user];
    
    
    
    
    
}

-(void)addGutView
{
    UIScrollView *mainScorllview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, DEVICE_WIDTH, DEVICE_HEIGHT)];
    mainScorllview.pagingEnabled = YES;
    mainScorllview.bounces = YES;
    mainScorllview.showsHorizontalScrollIndicator = NO;
    mainScorllview.showsVerticalScrollIndicator = false;
    mainScorllview.delegate = self;
    mainScorllview.userInteractionEnabled = true;
    mainScorllview.directionalLockEnabled = true;
    mainScorllview.backgroundColor = [UIColor colorWithRed:230.0/255.0 green:244.0/255.0 blue:209.0/255.0 alpha:1];
    [self.view addSubview:mainScorllview];
    
    NSArray * imageArray = @[[UIImage imageNamed:@"icon-address list-press@2x"],
                             [UIImage imageNamed:@"icon-address list-press@2x"],
                             [UIImage imageNamed:@"icon-address list-press@2x"],
                             [UIImage imageNamed:@"icon-address list-press@2x"]];
    
    mainScorllview.contentSize = CGSizeMake(DEVICE_WIDTH * imageArray.count,DEVICE_HEIGHT);
    
    for (int i = 0; i < imageArray.count; i++){
        UIImageView *imageViews = [[UIImageView alloc] init];
        imageViews.frame = CGRectMake(DEVICE_WIDTH*i, 0, DEVICE_WIDTH,  DEVICE_HEIGHT);
        imageViews.image = [imageArray objectAtIndex:i];
        [mainScorllview addSubview:imageViews];
    }
    
    UIButton *goInView = [UIButton buttonWithType:UIButtonTypeCustom];
    goInView.frame = CGRectMake(DEVICE_WIDTH*(imageArray.count-1), DEVICE_HEIGHT-120, DEVICE_WIDTH, 100);
    [goInView addTarget:self action:@selector(chageRootView) forControlEvents:UIControlEventTouchUpInside];
    [mainScorllview addSubview:goInView];
    
}

-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
    if (scrollView.contentOffset.x + scrollView.frame.size.width-40 >= (scrollView.contentSize.width)) {
        [self chageRootView];
    }
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    if (scrollView.contentOffset.x == DEVICE_WIDTH * 3) {
        [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(chageRootView) userInfo:nil repeats:NO];
    }
}
-(void)chageRootView
{
    AppDelegate *apd = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    [apd changeWindowRootViewColler];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
